__all__ = ['compress_image']
from PIL import Image


# 压缩图片
def compress_image(path, save, quality=85, ratio=0.9):
    """
    path: 文件地址
    save: 保存地址
    quality: 保存的质量，1-95
    ratio：压缩比率
    """
    im = Image.open(path)
    x, y = im.size
    out = im.resize((int(x * ratio), int(y * ratio)), Image.ANTIALIAS)
    try:
        out.save(save, optimize=True, quality=quality)
    except Exception as e:
        print(e)


if __name__ == '__main__':
    compress_image('D:\\a.jpg', 'D:\\b.jpg', 85, 0.8)
